package org.darkforest.listener;

import org.darkforest.common.logger.Logger;
import org.darkforest.common.util.SystemConstant;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContextEvent;

/**
 * Created by Justin on 15/1/18.
 */
public class SpringContextLoaderListener extends ContextLoaderListener {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        WebApplicationContext context = initWebApplicationContext(event.getServletContext());
        SpringContextHolder.getContextHolder().setContext(context);
        String basePath = event.getServletContext().getContextPath();
        Logger.debug(SpringContextInitializedListener.class, "basePath:" + basePath);
        event.getServletContext().setAttribute("basePath", basePath);
        event.getServletContext().setAttribute("alioss_path", SystemConstant.ALIOSS_PATH);
        event.getServletContext().setAttribute("pcweb_goodsDetailPath",SystemConstant.PCWEB_GOODS_DETAIL_PATH);
        event.getServletContext().setAttribute("pcweb_goodscommDetailPath",SystemConstant.PCWEB_GOODSCOMM_DETAIL_PATH);
        event.getServletContext().setAttribute("pcweb_path", SystemConstant.PCWEB_PATH);
    }

}
